package com.lans.linear;

/**
 * @author: lans
 * @date: 2025/2/24
 * @name: 刘宇
 */
public class ArrayQueue {
    //定义数组
    private int[] array;

    //数组大小
    private int maxSize;

    //头指针
    private int headPoint;

    //尾指针
    private int lastPoint;

    public ArrayQueue(int maxSize) {
        this.maxSize = maxSize;
        array = new int[maxSize];
        headPoint = -1;
        lastPoint = -1;
    }
    public boolean isEmpty() {
        return headPoint == lastPoint;
    }
    //队列是否已满
    public boolean isFull(){
        return lastPoint == maxSize-1;
    }

    //往队列中添加数据
    public void addQueue(int n){
        if (isFull()) {
            System.out.println("队列已满");
            return;
        }
        lastPoint++;
        array[lastPoint] = n;
    }

    //取元素
    public int getQueue(){
        if (isEmpty()) {
            throw new RuntimeException("空队列");
        }
        headPoint++;
        return array[headPoint];
    }
    //查询队列中的元素
    public void list(){
        if (isEmpty()) {
            throw new RuntimeException("空队列");
        }
        for(int i = 0 ;i<array.length;i++){
            System.out.printf("array[%d]=%d\n",i,array[i]);
        }
    }
    //查看队列中的第一个元素
    public int showHead(){
        if (isEmpty()) {
            throw new RuntimeException("空队列");
        }
        return array[++headPoint];
    }

    public static void main(String[] args) {
        ArrayQueue queue = new ArrayQueue(5);
        queue.addQueue(10);
        queue.addQueue(11);
        queue.addQueue(12);
        queue.addQueue(13);
        queue.addQueue(14);
        System.out.println(queue.showHead());
        queue.list();
    }
}